package com.application.Adapter;

import java.util.ArrayList;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.application.Activity.R;
import com.application.Adapter.ListPartAdapter.ViewPart;

	/**
	 * 
	 * @author h
	 *
	 */

public class ListPartAdapter extends ArrayAdapter<ViewPart>{
	private final Context _context;
	private final ArrayList<ViewPart> _partContent;
	int _resource;

	/**
	 * @param cContext :truyen activity hien hanh
	 * @param iTextViewResourceId : truyen id widget
	 * @param subject : truyen mang du lieu can load len custom view group
	 */
	public ListPartAdapter(Context cContext, int iTextViewResourceId,ArrayList<ViewPart> arrPart)
	{
		super(cContext,iTextViewResourceId,arrPart);
		this._context = cContext;
		_resource = iTextViewResourceId;
		_partContent = arrPart;
	}

	@Override
	public View getView(int iPosition, View vConvertView, ViewGroup vgParent) {
		final ViewPart vpListPart = _partContent.get(iPosition);
		
		View vRowView = vConvertView;
		if (vRowView == null) {
			LayoutInflater lInflater = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);;
			vRowView = lInflater.inflate(R.layout.listrow_listpart,null, true);
		}
		if(vpListPart !=null)
		{				
			TextView tvTitle = (TextView) vRowView.findViewById(R.id.part_tv_title);
			TextView tvNote = (TextView) vRowView.findViewById(R.id.part_tv_content);
			ImageView img_new = (ImageView)vRowView.findViewById(R.id.part_tv_imgnew);
			ImageView img_status = (ImageView) vRowView.findViewById(R.id.part_tv_imgstatus);
			
			img_new.setVisibility(View.INVISIBLE);	
			img_status.setVisibility(View.INVISIBLE);
			tvTitle.setText(vpListPart.getsViewTitle());
			tvNote.setText(vpListPart.getsViewContent());
			if(vpListPart._isStatus == true)
			{	
				img_new.setImageResource(R.drawable.img_new);
				img_new.setVisibility(View.VISIBLE);
			}
			if(vpListPart._isNotice == true)
			{	
				img_status.setImageResource(R.drawable.img_new);
				img_status.setVisibility(View.VISIBLE);
			}
		}
        return vRowView;
	}	
	
	
	public static class ViewPart{
		private String _partTitle; //tiêu đề part
		private String _partNote; //note part
		private int _idPart; 
		private boolean _isStatus; //status part cho biết part là mới hay cũ
		private boolean _isNotice; //Notice cho biết có thông báo hay không
		private int idDetailLearning;
		public ViewPart()
		{
			this._partTitle = "title";
			this._partNote = "note";
			this._isNotice = false;
			this._isStatus = false;
			this.set_idPart(0);
			this.idDetailLearning = 0;
		}
		public ViewPart(String s1,String s2, int id, boolean isstatus, boolean isnotice)
		{
			this.setsViewTitle(s1);
			this.setsViewContent(s2);
			this.set_idPart(id);
			this._isStatus = isstatus;
			this._isNotice = isnotice;
			Log.d("PEERDROID","view part");
		}

		public void setsViewTitle(String sViewTitle) {
			this._partTitle = sViewTitle;
		}

		public String getsViewTitle() {
			return _partTitle;
		}

		public void setsViewContent(String sViewContent) {
			this._partNote = sViewContent;
		}

		public String getsViewContent() {
			return _partNote;
		}

		public void setIdDetailLearning(int id) {
			this.idDetailLearning = id;
		}
		public int getIdDetailLearning() {
			return idDetailLearning;
		}
		public void set_idPart(int _idPart) {
			this._idPart = _idPart;
		}
		public int get_idPart() {
			return _idPart;
		}		
	}

}
